package com.example.javabasic.thread.classtwo.workthread.demo1;

import java.util.Random;

//消费者 工人
public class WorkerThread extends Thread {
    private final Channel channel;
    private static final Random random = new Random(System.currentTimeMillis());

    public WorkerThread(String name, Channel channel) {
        super(name);
        this.channel = channel;
    }

    @Override
    public void run() {

        for (int i = 0; true ; i++) {
            Request take = this.channel.take();
            //执行
            take.execute();
            try {
                Thread.sleep(random.nextInt(2000));
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
